<?php
###############   COPYLEFT GPLv3 LICENSE   ###############
##
## JFX Version 0.2.9
## Website Management Software
## www.jfxcms.com
##
## Copyright 2009 GPLv3 - http://www.opensource.org/licenses/gpl-3.0.html
##
## Anthony Gallon
## oi_antz@hotmail.com
##
## Permission is hereby granted to any person having a copy of this software
## to freely use and modify as required so long as the copyright notices
## and branding remain intact.
##
## Full license details available at http://www.jfxcms.com/license
##
###############   COPYLEFT GPLv3 LICENSE   ###############


$THEME->addBreadcrumb($this->adminUrl.'/domains/root/', $this->lang('ap_title_domains_delete'));


if(Antz_IntelliForm::submitted('delete-domain')){
    $id = (int) post('domain');

    if($DB->countRows($CONFIG->dbprefix.'domains', '1=1')==1){
        JFX::addError($this->lang('cannot_delete_only_domain'));
        return;
    }

    if(post('confirm')!='1'){
        $formFields = array(
            array(
                'type' => 'hidden',
                'name' => 'domain',
                'value' => $id
            ),
            array(
                'type' => 'hidden',
                'name' => 'confirm',
                'value' => 1
            ),
            array(
                'type' => 'submit',
                'name' => 'submitBtn',
                'value' => $this->lang('delete_domain_submit')
            )
        );

        $form = JFX::makeRapidForm($formFields, $this->lang('confirm_delete_domains', $DB->oneValue($CONFIG->dbprefix.'domains', 'domain_name', "id = '{$id}'")), 'delete-domain');
        echo '<h1>'.$this->lang('confirm_delete_heading').'</h1>';
        echo '<p>'.$this->lang('confirm_delete_description').'</p>';
        echo $form->render();
        return;
    }else{
        // ready to delete
        $pageid = $DB->oneValue($CONFIG->dbprefix.'pages', 'id', "is_domain = 1 AND domain_id = '{$id}'");
        $DB->delete($CONFIG->dbprefix.'blocks', "page_id = {$pageid}");
        $DB->delete($CONFIG->dbprefix.'pages', 'id = '.$pageid);
        $DB->delete($CONFIG->dbprefix.'domains', 'id = '.$id);
        JFX::addSuccess($this->lang('domain_deleted_success'));
        JFX::redirect(THIS_PAGE_URL);
    }
}



$deleteFormfields = array(
    array(
        'name' => 'domain',
        'type' => 'select',
        'label' => $this->lang('domain'),
        'options' => $domainOpts,
        'value' => post('domain')
    ),
    array(
        'name' => 'submitBtn',
        'type' => 'submit',
        'value' => $this->lang('delete_domain_submit'),
        'label' => '&nbsp;'
    )
);

$deleteForm = JFX::makeRapidForm($deleteFormfields, $this->lang('delete_domain_legend'), 'delete-domain');


echo '<div id="jfx-delete-domain">'.$deleteForm->render().'</div>';
echo '<div class="jfx-clear"></div>';






